import api from "../../../common/api";
import constant from '../../../common/constant';
// pages/cooperation/cooperativeAdvisory/cooperativeAdvisory.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    cooperationId: "", //当前电话中的合作id
    isVmShow: false, //虚拟电话弹层
    inviteInfo: {},
    list: [],
    emptyBox:true,
    toUserId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    getApp().globalData.loginPromise.then(() => {
      this.fetchHouse();
    });
  },

  fetchHouse() {
    this.setData({ list: [] });

    this.selectComponent("#com-scroll-content").fetchHouse(1, ({ page, pageSize }) => {
      return new Promise((resolve, reject) => {
        api.searchMyConsultCooperation({ page, pageSize: 10 }, ({ data }) => {
          data.handleData = (rows) => {
            this.setData({
              list: this.data.list.concat(rows),
            });
          };

          resolve(data);
        }, reject);
      });
    });
  },

  handleVmVisible(e) {
    const detail = e.detail 
    this.setData({
      isVmShow: detail.visible,
      cooperationId: detail.cooperationId,
      toUserId:detail.toUserId
      // inviteInfo: {
      //   houseInviteId: detail.houseInviteId,
      //   houseInviteUnionid: detail.houseInviteUnionid,
      // }
    });
  },

   


  // 合作咨询跳转
  onJumpPublish(){
    this.verifyPublish().then(() => {
      wx.gio('track', constant.RELEASE_FROM, {
        [constant.RELEASE_HOUSE_INFO]: '谁质询过我',
      })
      wx.navigateTo({
        url: "/pages/cooperation/publishIndex/publishIndex",
      });
    });
  },
  //权限判定
  verifyPublish() {
    let t = this;
    return new Promise((resolve, reject) => {
      let sessionUser = getApp().globalData.loginUserInfo.data.content.sessionUser;
      api.queryUserAuthInfo({userId: sessionUser.id,},(res) => {
          if (res && res.data && res.data.content) {
            let userInfo = res.data.content;
            if (userInfo.verified) {
              resolve();
            } else {
              wx.navigateTo({
                url: '/pages/cooperation/editCertification/editCertification',
              })
              reject();
            }
          } else {
            reject();
          }
        },
        () => {
          wx.showToast({
            icon: "none",
            title: "网络错误，请稍后再试~",
          });
        }
      );
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
});
